package com.wwinsoft.oa.dao.plan;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.wwinsoft.modules.orm.hibernate.HibernateDao;
import com.wwinsoft.oa.entity.plan.Workplan;

@Component
public class WorkPlanDao extends HibernateDao<Workplan, Long> {

    // add by sevenSpend 2011-11-30 start -->	
	private static final String DELETE_BY_GROUPID = "delete from t_work_plan where group_id = :groupId";
    private static final String UPDATE_BY_GROUPID = "update t_work_plan m set m.group_id = :newGroupId where m.group_id = :oldGroupId";
    
    /**
     * 查询属于该组织部门用户的工作计划并删除
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public int deleteByGroupId(String groupId) {
        Map paraMap = new HashMap();
        paraMap.put("groupId", groupId);
        Query sqlQuery = this.createSQLQuery(DELETE_BY_GROUPID, paraMap);
        return sqlQuery.executeUpdate();
    }
    
    /**
     * 查询属于该组织部门用户的工作计划并更改部门ID
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public int updateGroupId(String oldGroupId, String newGroupId) {
        Map paraMap = new HashMap();
        paraMap.put("oldGroupId", oldGroupId);
        paraMap.put("newGroupId", newGroupId);
        Query sqlQuery = this.createSQLQuery(UPDATE_BY_GROUPID, paraMap);
        return sqlQuery.executeUpdate();
    }
    // <-- add by sevenSpend 2011-11-30 end
	
}
